package com.ruoyi.system.utils;

import com.ruoyi.system.domain.*;

import java.util.*;

/**
 * Created On : 2024/4/8.
 * Author : xuliang
 * Description: DataByYear
 * <p>
 */
public class DataByYear {

    public static Map<Integer, List<ProcurementDetail>> detailByYear(List<ProcurementDetail> dataList) {
        // 创建一个当前年份的日历对象
        Calendar currentYearCalendar = Calendar.getInstance();
        int currentYear = currentYearCalendar.get(Calendar.YEAR);

        // 创建一个最近年份的映射，将当前年份及之前的年份与空列表关联起来
        Map<Integer, List<ProcurementDetail>> dataByYear = new HashMap<>();
        for (int year = 2020; year <= currentYear; year++) {
            dataByYear.put(year, new ArrayList<>());
        }

        // 将传入的数据按照创建时间分组
        for (ProcurementDetail data : dataList) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(data.getCreateTime());
            int year = calendar.get(Calendar.YEAR);

            if (dataByYear.containsKey(year)) {
                dataByYear.get(year).add(data);
            }
        }
        return dataByYear;
    }

    public static Map<Integer, List<Direct>> directByYear(List<Direct> dataList) {
        // 创建一个当前年份的日历对象
        Calendar currentYearCalendar = Calendar.getInstance();
        int currentYear = currentYearCalendar.get(Calendar.YEAR);

        // 创建一个最近年份的映射，将当前年份及之前的年份与空列表关联起来
        Map<Integer, List<Direct>> dataByYear = new HashMap<>();
        for (int year = 2020; year <= currentYear; year++) {
            dataByYear.put(year, new ArrayList<>());
        }

        // 将传入的数据按照创建时间分组
        for (Direct data : dataList) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(data.getCreateTime());
            int year = calendar.get(Calendar.YEAR);

            if (dataByYear.containsKey(year)) {
                dataByYear.get(year).add(data);
            }
        }
        return dataByYear;
    }

    public static Map<Integer, List<Labor>> laborByYear(List<Labor> dataList) {
        // 创建一个当前年份的日历对象
        Calendar currentYearCalendar = Calendar.getInstance();
        int currentYear = currentYearCalendar.get(Calendar.YEAR);

        // 创建一个最近年份的映射，将当前年份及之前的年份与空列表关联起来
        Map<Integer, List<Labor>> dataByYear = new HashMap<>();
        for (int year = 2020; year <= currentYear; year++) {
            dataByYear.put(year, new ArrayList<>());
        }

        // 将传入的数据按照创建时间分组
        for (Labor data : dataList) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(data.getCreateTime());
            int year = calendar.get(Calendar.YEAR);

            if (dataByYear.containsKey(year)) {
                dataByYear.get(year).add(data);
            }
        }
        return dataByYear;
    }

    public static Map<Integer, List<Indirect>> indirectByYear(List<Indirect> dataList) {
        // 创建一个当前年份的日历对象
        Calendar currentYearCalendar = Calendar.getInstance();
        int currentYear = currentYearCalendar.get(Calendar.YEAR);

        // 创建一个最近年份的映射，将当前年份及之前的年份与空列表关联起来
        Map<Integer, List<Indirect>> dataByYear = new HashMap<>();
        for (int year = 2020; year <= currentYear; year++) {
            dataByYear.put(year, new ArrayList<>());
        }

        // 将传入的数据按照创建时间分组
        for (Indirect data : dataList) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(data.getCreateTime());
            int year = calendar.get(Calendar.YEAR);

            if (dataByYear.containsKey(year)) {
                dataByYear.get(year).add(data);
            }
        }
        return dataByYear;
    }

    public static Map<Integer, List<Output>> outputByYear(List<Output> dataList) {
        // 创建一个当前年份的日历对象
        Calendar currentYearCalendar = Calendar.getInstance();
        int currentYear = currentYearCalendar.get(Calendar.YEAR);

        // 创建一个最近年份的映射，将当前年份及之前的年份与空列表关联起来
        Map<Integer, List<Output>> dataByYear = new HashMap<>();
        for (int year = 2020; year <= currentYear; year++) {
            dataByYear.put(year, new ArrayList<>());
        }

        // 将传入的数据按照创建时间分组
        for (Output data : dataList) {
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(data.getCreateTime());
            int year = calendar.get(Calendar.YEAR);

            if (dataByYear.containsKey(year)) {
                dataByYear.get(year).add(data);
            }
        }
        return dataByYear;
    }

}
